<script>
	var dodelete='__URL__/dodelete';
	var dobatchdelete='__URL__/dobatchdelete';
	var doalldelete='__URL__/doalldelete';
</script>
<!--table部分-->
<div class='col-md-12'>
	<div class="panel panel-default">
	  <div class="panel-body">
	    <div class="col-md-3"><a href='__ROOT__/Uploads/qksomething/example1.xls' class='btn btn-warning'>下载示例</a></div>
	    <div class='col-md-3'><button class='btn btn-info' id='upld'>上传数据</button></div>
	    <div class='col-md-3'><button class='btn btn-success' id='export2xls' >导出结果到EXCEL</button><a target="_blank" id='export_a' style='display: none'><span id='export_span'>弹到新窗口</span></a></div>
	    <div id='fenxijieguo'></div>
	    <!-- pt start -->
	    <link rel="stylesheet" type="text/css" href="__PUBLIC__/etc/huploadify/html5uploader.css"/>
	    <script type="text/javascript" src="__PUBLIC__/etc/huploadify/jquery.html5uploader.js"></script>
	    <script>var dogivetail='__APP__/Hupldf/dogivetail'</script>
	    <script type="text/javascript">
	    $(function(){
	        $('#upload').html5uploader({
	            fileTypeExts:'',//考虑到兼容性，就都可以传吧，但是需要在后期进行后缀名的判断
	            auto:true,
	            multi:false,
	            removeTimeout:0,
	            url:'__APP__/Hupldf/upload/folder/qksomething',//
	            onUploadStart:function(){
	                //alert('开始上传');
	                $('#loading').trigger('click');
	                var timestamp = (new Date()).valueOf();
	            },
	            onInit:function(){
	                //alert('初始化');
	            },
	            onUploadComplete:function(file){
	                
	                $.post(
	                    '__URL__/fenxidaoru',
	                    {},
	                    function(data){
	                        $('#loading_cancel').trigger('click');
	                        var rslt=data['rslt'];
	                        if(rslt==1){
	                        	msg('导入成功！共导入'+data['tongji_success']+'条',1);
	                        	
	                        }else if(rslt==2){
	                        	var arr_error=data['arr_error'];
	                        	var str="<br><br><b style='color:#f00'>已成功导入"+data['tongji_success']+"条数据。其中以下数据有问题，请检查！</b><br><br><table class='table  table-striped  table-bordered table-hover'><tr><th>EXCEL中的序号</th><th>对方姓名</th><th>错误原因</th></tr>";
	                        	for(var i=0;i<arr_error.length;i++){
	                        		var xuehao=arr_error[i]['xuhao'];
	                        		var qkcustomernm=arr_error[i]['qkcustomernm'];
	                        		var beizhu=arr_error[i]['beizhu'];
	                        		str=str+"<tr><td>"+xuehao+"</td><td>"+qkcustomernm+"</td><td>"+beizhu+"</td></tr>";
	                        	}
	                        	str=str+"</table>";
	                        	msg(str,1);
	                        }
	                        
	                    },
	                    'json'
	                );
	            }
	        });
	    });
	    </script>
	    <div id="upload" style='display:none'></div>
	  </div>
	  <script type="text/javascript">
		$(function(){
			$('#upld').click(function(){
				$('#uploadfilebtn').trigger('click');
			})
		})
		</script>

	</div>
	<!--开始-->
	<table class='table table-hover table-striped table-bordered table-condensed' id='NBtb' style="font-size:11px">
		<thead>
			<tr style="background-color: #337ab7;color:#fff">
				<th>#</th>
				<th>序号</th>
				<volist name='thls' id='thv'>
					<?php if($thv=='处理结果'||$thv=='物流跟踪'){ ?>
					<th style='width:10%'>{$thv}</th>
					<?php }else{ ?>
					<th>{$thv}</th>
					<?php } ?>
				</volist>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
			<volist name='mls' id='mv'>
				<tr>
					<td><input type='checkbox'  autocomplete="off" id="ckb_<?php echo $mv[$mdmklow.'id'] ?>" class='ckb'></td>
					<td>{$pagestart+$i}</td>
					<?php foreach ($mv as $key => $value) {
						if(!in_array($key,$hide_fld)){
					?>
					<?php if($key=='qkpic'){ ?>
					<td><a href='#' onclick="showpic('{$value}')" ><?php if($value){ ?><img src="{$value}" style='width:50px;height:50px'><?php } ?></a></td>
					<?php continue; } ?>
						<td>{$value}</td>
					<?php 
						}
					} ?>
					<td>
					<?php if($atho['athv']){ ?><a class='btn btn-success btn-sm' href="__URL__/view/id/<?php echo $mv[$lowmdmk.'id'] ?>">查看</a><?php } ?>
					<?php if($atho['athm']){ ?><a class='btn btn-warning btn-sm' href="__URL__/update/id/<?php echo $mv[$lowmdmk.'id'] ?>">修改</a><?php } ?>
					<?php if($atho['athd']){ ?><a class='btn btn-danger btn-sm' onclick="dlt(<?php echo $mv[$lowmdmk.'id'] ?>)" >删除</a><?php } ?>
					</td>
				</tr>
			</volist>
			
		</tbody>
	</table>
	<div class="panel panel-default">
	  <div class="panel-body" style="padding:0px 10px">
		<div class="checkbox">
		<label>
		  <input type="checkbox" id='thispageallselect'  autocomplete="off"> 本页全选
		</label>
		</div>
	  </div>
	</div>
	
	<!--结束-->
	{$page}
	<br><br><?php if($atho['atha']){ ?><a class='btn btn-primary' href='__URL__/update/id/0'>添加</a><?php } ?>
	<?php if($atho['athd']){ ?>
	<button class='btn btn-danger' id='batchdelete'>批量删除</button>
	<button class='btn btn-warning' id='alldelete' style="display:none">全部删除</button>
	
	<?php } ?>
</div>

<script type="text/javascript">

</script>
<script type="text/javascript">$("#NBtb thead").smartFloatTB();</script>
<script type="text/javascript">
function dlt(id){
	if(confirm("{$deleteconfirm}")){
		$.ajax({
            'type': 'GET',
            'url':dodelete,
            'async':false,  
            'contentType': 'application/json',
            'data': {'id':id},
            'dataType': 'json',
            'success': function(data) {
            	msg('删除成功！',1);
            	console.log("success");
            },
            'error':function() {
                console.log("error");
            }
        });
	}
}
</script>


<!--#################-->
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal_previewquanjietu" style='display: none' id='previewquanjietu'>
  Launch demo modal
</button>

<!-- Modal -->
<div class="modal" id="myModal_previewquanjietu" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog" style='padding-top:50px' id='previewquanjietudialog'>
    <div class="modal-content" id='previewcontent'>
      <div class="modal-header">
      <button type="button" class="close close_preview" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
      <h4 class="modal-title">预览</h4>
    </div>
      <div class="modal-body">
                
        <div  id='previewquanjietuctt' ></div>
        
      </div>
      <div class="modal-footer">
        <!--<button type="button" class="btn btn-success" id="copy_preview" >复制</button>-->
        <button type="button" class="btn btn-default close_previewquanjietu" data-dismiss="modal" >关闭</button>
        
      </div>
    </div>
  </div>
</div>

<script>
function showpic(picaddr){
  $('#previewquanjietuctt').html("<img style='width:100%' src='"+picaddr+"'>");

  $('#previewquanjietu').trigger('click');
  
  
}

</script>

<script>
$(function(){
	$('#export2xls').click(function(){
	  
	  //处理cdt
	  var cdtls=$('.cdt');
	  for(var i=0;i<cdtls.size();i++){
	    cdto=cdtls[i];var id_cdt=$(cdto).attr('id');
	    if($.trim($(cdto).val())!=''){
	      obj[id_cdt]=$.trim($(cdto).val());
	    }
	  }
	  //处理spccdt
	  var spccdtls=$('.spccdt');
	  for(var i=0;i<spccdtls.size();i++){
	    spccdto=spccdtls[i]; 
	    var cls=$(spccdto).attr('class');
	    if(cls.indexOf('primary')!=-1){
	      obj[i+'_nb_spccdt']=$(spccdto).val();
	    }
	  }
	  //处理fld,未选中的fld需要从里头除名
	  var fldls=$('.fld');
	  for(var i=0;i<fldls.size();i++){
	    fldo=fldls[i];
	    if($(fldo).is(':checked')==false){
	      var id_fld=$(fldo).attr('id');
	      id_fld=id_fld.split('_nb_fld')['0'];
	      fldu=fldu.replace(id_fld+'-','');
	    }
	  }
	  obj['nb_fld']=fldu;
	  
	  //处理odr
	  var odrls=$('.odr');
	  for(var i=0;i<odrls.size();i++){
	    odro=odrls[i];var id_odr=$(odro).attr('id');
	    if($(odro).val()!=''){
	      obj[id_odr]=$(odro).val();
	    }
	  }
	  //处理lmt
	  obj['nb_lmt']=$('#nb_lmt').val();

	  //处理mdmk
	  obj['nb_mdmk']="{$mdmk}";

	  $.ajax({
	      'type': 'GET',
	      'url':dosearch,
	      'async':false,  
	      'contentType': 'application/json',
	      'data': obj,
	      'dataType': 'json',
	      'success': function(data) {
	      	var url=data['url'];
	      	//把query给替换掉
	      	url=url.replace("query", "export");
	        $('#export_a').attr('href',url);
	       	$('#export_span').trigger('click');
	        console.log("success");
	      },
	      'error':function() {
	        console.log("error");
	      }
	  });
	})

	//#############
	$('.spccdt').click(function(){
	  var cls=$(this).attr('class');
	  if(cls.indexOf('info')!=-1){
	    cls=cls.replace('info','default');
	  }else{
	    cls=cls.replace('default','info');
	  }
	  $(this).attr('class',cls);
	})

})
</script>
<script type="text/javascript">
$(function(){
	$('#batchdelete').click(function(){
		if(confirm('确定要批量删除吗？')){
			var ckbls=$('.ckb');
			var id_str='-';
			for(var i=0;i<ckbls.size();i++){
				ckbo=ckbls[i];var id_ckb=$(ckbo).attr('id').split('ckb_')[1];
				if($(ckbo).is(':checked')){
				  id_str=id_str+id_ckb+'-';
				}
			}
			if(id_str!='-'){
				$.ajax({
				    'type': 'GET',
				    'url':dobatchdelete,
				    'async':false,  
				    'contentType': 'application/json',
				    'data': {'id_str':id_str},
				    'dataType': 'json',
				    'success': function(data) {
				    	msg('批量删除成功！',1);
				    	console.log("success");
				    },
				    'error':function() {
				        console.log("error");
				    }
				});
			}
		}
	})
	$('#alldelete').click(function(){
		if(confirm('确定要全部删除吗？')){
			
			$.ajax({
			    'type': 'GET',
			    'url':doalldelete,
			    'async':false,  
			    'contentType': 'application/json',
			    'data': {},
			    'dataType': 'json',
			    'success': function(data) {
			    	msg('全部删除成功！',1);
			    	console.log("success");
			    },
			    'error':function() {
			        console.log("error");
			    }
			});
			
		}
	})

	$("#thispageallselect").change(function() { 
		if($(this).is(':checked')==true){
			$('.ckb').prop("checked",true);
		}else{
			$('.ckb').prop("checked",false);
		}
	});
	
})
</script>
